import moment from 'moment-timezone';

export const INPUT_TYPE_ENUM = {
    OTHER: 0,
    MINUTE: 4,
    HOUR: 5,
    DAY: 6,
    WEEK: 7,
    MONTH: 8,
    SINGLE_DAY: 9
};

/**
 * 是否时间段枚举
 * @param {string} value 判断的值: 0 1 2 3 都不是日期
 */
export function isTimeRange(value) {
    if (value === INPUT_TYPE_ENUM.MINUTE
        || value === INPUT_TYPE_ENUM.HOUR
        || value === INPUT_TYPE_ENUM.DAY
        || value === INPUT_TYPE_ENUM.WEEK
        || value === INPUT_TYPE_ENUM.MONTH
    ) {
        return true;
    }
    return false;
}
export function isTimePoint(value) {
    if (value === INPUT_TYPE_ENUM.SINGLE_DAY) {
        return true;
    }
    return false;
}

// 时间段枚举
export const RANGE_NAME_ENUM = {
    MINU_60: '近60分钟',
    HOUR_24: '近24小时',
    DAY_1: '当日',
    DAY_2: '近2日',
    DAY_3: '近3日',
    DAY_4: '近4日',
    DAY_5: '近5日',
    DAY_6: '近6日',
    DAY_7: '近7日',
    WEEK_1: '近1周',
    WEEK_2: '近2周',
    WEEK_3: '近3周',
    WEEK_4: '近4周',
    MONT_1: '近1月',
    MONT_2: '近2月',
    MONT_3: '近3月',
    MONT_4: '近4月',
    MONT_5: '近5月',
    MONT_6: '近6月',

    NONE: '空'
};

// 时间段moment值
function getRangeDate(value) {
    const now = moment();
    // 当前时间的6小时内
    const endOfToday = moment().endOf('day');
    const map = new Map([
        [
            RANGE_NAME_ENUM.MINU_60,
            [moment().subtract(60, 'minute'), now]
        ],
        [
            RANGE_NAME_ENUM.HOUR_24,
            [moment().subtract(24, 'hour'), now]
        ],
        [
            RANGE_NAME_ENUM.DAY_1,
            // 当日，即今日开头 到今日结束
            [moment().startOf('day'), endOfToday]
        ],
        [
            RANGE_NAME_ENUM.DAY_2,
            // 昨天与今天
            [
                moment().subtract(1, 'days')
                    .startOf('day'), endOfToday
            ]
        ],
        [
            RANGE_NAME_ENUM.DAY_3,
            [
                moment().subtract(2, 'days')
                    .startOf('day'), endOfToday
            ]
        ],
        [
            RANGE_NAME_ENUM.DAY_4,
            [
                moment().subtract(3, 'days')
                    .startOf('day'), endOfToday
            ]
        ],
        [
            RANGE_NAME_ENUM.DAY_5,
            [
                moment().subtract(4, 'days')
                    .startOf('day'), endOfToday
            ]
        ],
        [
            RANGE_NAME_ENUM.DAY_6,
            [
                moment().subtract(5, 'days')
                    .startOf('day'), endOfToday
            ]
        ],
        [
            RANGE_NAME_ENUM.DAY_7,
            [
                // (当前时间－6天)的凌晨0点 到 当前时间的晚上23：59----->正好7天
                moment().subtract(6, 'days')
                    .startOf('day'), endOfToday
            ]
        ],
        [
            RANGE_NAME_ENUM.WEEK_1,
            [moment().subtract(1, 'week'), now]
        ],
        [
            RANGE_NAME_ENUM.WEEK_2,
            [moment().subtract(2, 'week'), now]
        ],
        [
            RANGE_NAME_ENUM.WEEK_3,
            [moment().subtract(3, 'week'), now]
        ],
        [
            RANGE_NAME_ENUM.WEEK_4,
            [moment().subtract(4, 'week'), now]
        ],
        [
            RANGE_NAME_ENUM.MONT_1,
            [moment().subtract(1, 'month'), now]
        ],
        [
            RANGE_NAME_ENUM.MONT_2,
            [moment().subtract(2, 'month'), now]
        ],
        [
            RANGE_NAME_ENUM.MONT_3,
            [moment().subtract(3, 'month'), now]
        ],
        [
            RANGE_NAME_ENUM.MONT_4,
            [moment().subtract(4, 'month'), now]
        ],
        [
            RANGE_NAME_ENUM.MONT_5,
            [moment().subtract(5, 'month'), now]
        ],
        [
            RANGE_NAME_ENUM.MONT_6,
            [moment().subtract(6, 'month'), now]
        ],
        [
            RANGE_NAME_ENUM.NONE,
            []
        ],
    ]);
    // 默认近7日
    return map.get(value) || map.get(RANGE_NAME_ENUM.DAY_7);
}

export default getRangeDate;

